package com.atguigu.gulimall.order.controller;

import java.util.Arrays;
import java.util.Map;

import com.atguigu.gulimall.order.feign.CouponFeign;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import com.atguigu.gulimall.order.entity.OmsOrderEntity;
import com.atguigu.gulimall.order.service.OmsOrderService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;

import javax.annotation.Resource;


/**
 * 订单表
 *
 * @author zhangxiaosan
 * @email 424207204@qq.com
 * @date 2021-04-11 13:50:06
 */
@RefreshScope
@RestController
@RequestMapping("order/omsorder")
public class OmsOrderController {
    @Autowired
    private OmsOrderService omsOrderService;

    @Autowired
    CouponFeign couponFeign;

    @Value("${name}")
    private String name;

    @RequestMapping("/test")
    public R test(){
        R list = couponFeign.list();
        return R.ok().put("data",list);
    }

    @RequestMapping("/test1")
    public R test1(){

        return R.ok().put("data",name);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = omsOrderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		OmsOrderEntity omsOrder = omsOrderService.getById(id);
        return R.ok().put("omsOrder", omsOrder);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody OmsOrderEntity omsOrder){
		omsOrderService.save(omsOrder);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody OmsOrderEntity omsOrder){
		omsOrderService.updateById(omsOrder);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		omsOrderService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @GetMapping("/getOrderById/{orderSn}")
    public OmsOrderEntity getOrderBySn(@PathVariable("orderSn")String orderSn){
        OmsOrderEntity byId = omsOrderService.getOne(new QueryWrapper<OmsOrderEntity>().eq("order_sn",orderSn));
        return byId;
    }

}
